package com.CloudDream.Command;

import com.CloudDream.Constants.PlayerTabListEnum;
import com.CloudDream.Constants.TabListEnum;
import com.CloudDream.MoonCake;
import com.handy.lib.annotation.HandyCommand;
import com.handy.lib.command.HandyCommandFactory;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@HandyCommand(name = "mooncake")
public class MoonCakeCommand implements TabExecutor {
    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
        if (args.length < 1) {
            return sendHelp(commandSender);
        }

        boolean rst1 = HandyCommandFactory.getInstance().onCommand(commandSender, command, label, args, MoonCake.prefix + "§c你没有权限执行该命令");
        if (!rst1)
            return sendHelp(commandSender);
        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
        List<String> completions = new ArrayList<>();
        List<String> commands = PlayerTabListEnum.returnList(args, args.length);
        if (sender.hasPermission("mooncake.reload"))
            commands = TabListEnum.returnList(args, args.length);
        if (commands == null)
            return null;
        StringUtil.copyPartialMatches(args[args.length - 1].toLowerCase(), commands, completions);
        Collections.sort(completions);
        return completions;
    }

    public boolean sendHelp(CommandSender sender) {
        if(!sender.hasPermission("mooncake.reload")){
            sender.sendMessage("§7§m==============================");
            sender.sendMessage("");
            sender.sendMessage("§7月饼是具有代表性的中国传统糕点之一");
            sender.sendMessage("§7乃八月十五中秋节节日食俗");
            sender.sendMessage("");
            sender.sendMessage("§d§l2021年中秋快乐！ ");
            sender.sendMessage("");
            sender.sendMessage("§a● §b/mooncake §etable §7§l- §7打开月饼合成界面");
            sender.sendMessage("§a● §b/mooncake §egetgift §7§l- §7获取一个月饼礼盒");
            sender.sendMessage("§a● §b/mooncake §egivegift §d<玩家ID> §7§l- §7给指定玩家赠送一个月饼礼盒");
            sender.sendMessage("§a● §b/mooncake §erecipe §d<月饼> §7§l- §7查看月饼合成配方");
            sender.sendMessage("§a● §b/mooncake §egivemooncake §d<玩家ID> §7§l- §7将手中的月饼赠送给指定在线玩家");
            sender.sendMessage("§a● §b/mooncake §egivegift §d<玩家ID> §7§l- §7将手中的中秋礼盒赠送给指定在线玩家");
            sender.sendMessage("§a● §b/mooncake §egift §7§l- §7将背包中的7种月饼合成为一个礼盒，可赠送");
            sender.sendMessage("");
            sender.sendMessage("§7§m==============================");
            return true;
        }

        sender.sendMessage("§7§m==============================");
        sender.sendMessage("");
        sender.sendMessage("§7月饼是具有代表性的中国传统糕点之一");
        sender.sendMessage("§7乃八月十五中秋节节日食俗");
        sender.sendMessage("");
        sender.sendMessage("§d§l2021年中秋快乐！ ");
        sender.sendMessage("");
        sender.sendMessage("§a● §b/mooncake §etable §7§l- §7打开月饼合成界面");
        sender.sendMessage("§a● §b/mooncake §cgetgift §7§l- §7获取一个月饼礼盒");
        sender.sendMessage("§a● §b/mooncake §cgivegift §d<玩家ID> §7§l- §7给指定玩家赠送一个月饼礼盒");
        sender.sendMessage("§a● §b/mooncake §crecipe <月饼> §7§l- §7查看月饼合成配方");
        sender.sendMessage("§a● §b/mooncake §cgivemooncake §d<玩家ID> §7§l- §7将手中的月饼赠送给指定在线玩家");
        sender.sendMessage("§a● §b/mooncake §cgivegift §d<玩家ID> §7§l- §7将手中的中秋礼盒赠送给指定在线玩家");
        sender.sendMessage("§a● §b/mooncake §cgift §7§l- §7将背包中的7种月饼合成为一个礼盒，可赠送");
        sender.sendMessage("§a● §b/mooncake §cadd §d<玩家ID> <月饼id> §7§l- §7给玩家一个月饼");
        sender.sendMessage("§a● §b/mooncake §ctake §d<玩家ID> <月饼id> §7§l- §7扣除玩家一个月饼");
        sender.sendMessage("§a● §b/mooncake §creload §7§l- §7重载配置文件");
        sender.sendMessage("");
        sender.sendMessage("§7§m==============================");
        return true;
    }
}
